package com.example.myredisinaction.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.*;

@Component
@Slf4j
public class AutoCompleteDemo implements CommandLineRunner {

    @Autowired
    RedisTemplate<String, Serializable> redisTemplate;


    @Override
    public void run(String... args) throws Exception {
        ZSetOperations<String, Serializable> zSetOp = redisTemplate.opsForZSet();
        Long len = zSetOp.zCard("names");
        if (len != null && len == 0) {
            List<String> nameList = new ArrayList<>();
            Random random=new Random();
            for (int i = 0; i < 50; i++) {
                int i1 = random.nextInt(7) + 3;
                StringBuilder builder = new StringBuilder();
                for (int j = 0; j < i1; j++) {
                    builder.append((char) (random.nextInt(26) + 97));
                }
                nameList.add(builder.toString());
            }
            log.info(nameList.toString());

            log.info("开始插入数据");
            for (String name : nameList) {
                zSetOp.add("names", name, 0);
            }
            log.info("插入数据成功");
        }
//        Set<Serializable> names = zSetOp.range("names", -10, -1);
//        log.info(names.toString());
    }

//    private static final List<String> names= Arrays.asList("kbud","whxtovu","pqt","ebl","iugpyu","ayakwqynk","pmfbqvi","skseuc","xbtqtm","hrms","ackxiwfcn","nmu","jackhitx","wifeneiv","ciujz","ysvfmtul","jjbujfask","wyjhvzdwu","bjyi","ncfwyjhcv","stvzuwcza","agdaca","yxlefore","nbmxba","xryabo","yeoyym","kwgrb","dfslk","iez","aerhizant","znzkuuyqh","svjnnzzrv","fbay","xec","dqpbgw","tcakvrssy","ucmmlgl","ewv","qmvturk","cqax","salg","ykqhiccn","xmtmflpvj","fakwit","bqbgp","oirhkhl","fgasugi","wuarx","xbfpazzf","onhv","wjgbkpev","fehq","ycugvy","fdh","kyee","uohcbxc","mdacmjqis","hbpgbua","ounq","egzyleam","ygnqzvzop","agzd","xqwdaevpd","emrzq","yhgkwyzrr","vqtrvx","bxj","vapduwz","lpdhne","klin","rzj","lbstp","jxrffjptr","gsgxqcz","baqufyl","xmkwgfxjg","chmrjtbax","zjtdptck","onroag","ffkkfsjuq","rcdonpif","gyzsh","obomq","vatoxgq","qmjvbk","vyxyfu","ybs","xnica","pyxdmuocc","nrpvq","zep","yserce","uxvec","vovgo","culxza","vmf","luemkjauo","ktuwp","dozuq","zfzutlkt","cauto","ezqf","aveaxz","zzzvl","kah","wupmh","ttjaumyq","dpa","mbit","mkian","cxxlqw","wsd","nwpl","xsf","cpzfsgi","wga","ryvt","zysnjzevz","foo","wninbyokq","hhhsrct","iyl","sxdaqx","trhwye","ndwve","mwjj","xiuexnh","frrqpd","pctahjpr","kogunvh","zyn","tcntk","yirxpje","hydudv","xdq","qdqkh","vpluzvi","wkcsawzg","erla","gwnzs","txkk","hxinaxh","swq","lcwakvwj","fyafbuocm","bpcitwk","hlk","bamlojb","ezlrp","gjws","jnpye","axa","bip","ermtsan","stkhmhd","pum","fccizygm","kmdxy","layoc","beixqcmlk","sikxayybm","jmliww","rhfw","gvxetgpfp","qiz","erc","llouoinwa","jafsqqk","idzjnts","fikrjswe","reuy","cxglk","piwztqk","vjpnu","oanre","ukupy","yoklnh","hizzxj","gtdurokqo","wumbcnxb","itqclscb","uytvcatxy","gzjpqcbgk","vgnhme","ioisteeqw","ikswwqj","hjoqq","glcq","nokbwl","uwvejxhxd","iifj","pojzwn","voiucup","mqi","dbl","ztylly","jdnvkccv","lrysu","wzmx","ultiym","xqblqxvz","wpe","uqa","tjsga","krkxorj","acevoje","ave","inlf","fttp","uqshwvctp","rqlb","irtrbktyb","dmh","gasxzi","ykz","adp","nzv","gsbccy","zeh","pebxahcza","wtjhmily","ypxrapr","qyx","qdze","zfxujtpxd","urwomxnr","wifunx","uzpv","upmpnigfg","ipqgnjkjv","ifwgfgi","sek","anitxds","sckruezem","cljvz","zorraoes","brpcf","ruyizpyr","bcgr","fbgrg","oamdx","wtcpm","hyuvywm","ilmbwar","iqzjranz","zzgjg","nqmexwcq","yobevvyez","kopomfpd","ksihoojq","cyomhygar","gmzatfc","gpzweo","gbfzxgt","uwdxtetz","mglfpcn","xsd","zcsl","hyn","jxmvwf","wptiu","tjzd","kwowfdlb","yufxpnuf","pbccuizdt","wamkh","newauta","msvpjmei","nebod","kuw","xjy","smfjun","emikfdl","ikeldpvek","bcxp","hdclkf","lyjqmnl","soqx","zws","ooukzb","eaapnxc","acufkddd","yqu","cpuytbc","lwnbfaiec","viq","hdb","jbx","hoft","zsnzlyvr","cnuklccrv","nabo","mojodskhl","ebcvh","kohdipiq","nyzztoj","cmrpfx","wqvimxspe","xhl","dxixlao","yxsesag","ykwljskwl","otsjzete","efncg","vgaboqp","gdjlfz","nmnel","eenxvq","ylt","qzkuph","wvkusxufu","fdzbrmvy","odgap","uyzuvbp","czrizqxn","dvsf","znznlmwd","lsz","ckcbw","ntn","odmbczgnw","nzjfnyw","nhl","cail","jtranrsj","gtgpko","imrbkqta","swge","ruflsgtbn","wfd","anivpywj","wukizan","pfwtck","ldojai","cuwnvqmym","asrzirvge","cyxeiuj","aukgxjm","vthqno","ntou","wgjcscsdr","dgl","bvvrkebx","hduhfao","fsqulit","trhoiwp","xtaf","aajszlj","ika","fojsvzj","fpzczdy","ipedhrh","mdh","rjfpe","xleoa","hpefcwh","reng","suidmnze","jnxhh","xjbyit","dvphp","blmwvch","jhxslwywi","cla","zxot","ujnhr","kkjafxtmw","ncvhw","xdqmgsn","osrsy","fbiwnsdo","diuorlgrh","xmwptfvr","ohqcugslr","nme","qiyp","qai","zhhcmk","gcygk","qcth","enuuff","pzjanz","tsym","bllad","kexdlec","jcgfp","oqp","fwcxb","qslcdk","ucdhfsme","nuccqnxso","oxms","vkgdqy","ejoufwnbh","cebgkk","atk","otq","hujbnre","jmyfogmtn","lihi","irrczvfh","qblajiwee","ehwbc","nfkertir","ourtn","rvargdr","mns","govbiwkc","rvyitoe","afn","ebwotk","jvsvqanbl","eztdqyrve","taeansra","hvqxggac","rggvuaqx","pyxxdluy","fargxrths","tyomdohmp","snoflh","odjxgitn","htlrw","xofui","zrklmzvyz","ies","qgemx","tiqsaud","lheomhpl","wtqkmjex","tgprgcj","rzztm","fpxzc","ahk","sqlgvuh","bugvxvk","iahbg","migtwukph","jrsusoy","jsnvil","kpfhjn","pjq","gnyprvta","vrflafc","yidhknrs","uivnnv","wmjucodyq","kse","kpruud","uyep","qlc","kismvx","szs","sgywzjvck","cls","kwvw","ljzfwdnm","fpnlag","jqypys","jgy","gxy","radceymk","aodqymoen","nxzraqjm","jmkk","switrlz","aafo","nrgscknn","wzwkq","pzf","jmlknrmz","dotgnmuvd","tev","bzarpwj","hqlfvhp","wmjbbzvr","urqpiyqge","zvmjdemk","mjnriprdc","cdmzgyl","seuwqg","cwxapkn","fxqatkjz","cpiyaz","igmkv","klikt","dhpukecrk","qbabvsjqj","nlnytvcfg","eag","pwmr","cyzpjfa","furr","evihooop","tql","pyoeuo","hniktc","eit","unkyyi","srnfz","stryuy","woplonb","shmxgv","puoihw","stymeonha","hfytbhcq","dpq","ersy","jxco","svaujxo","tmzas","qeo","moaq","tqhsh","qkjnvqdas","ovh","nxlrvene","jtulbl","dvkeuedxu","jfpsdce","vtjnbyaa","jxsgwviwf","zirtm","jon","tthq","rspch","azyemt","hraaph","fmmcrnmm","tubwpp","gcmirdzhq","dalnh","hgld","dgg","quacva","cmbug","uaqkb","mvchhidq","uqpmys","ljkckv","yryksu","ibhgrcjya","aqyf","tgnau","grvq","dtebr","adiniof","gvdmphyz","ruqgpahq","jkag","urvvnsden","xhlidb","mrcpo","ppbq","whjotdcy","hyl","pkyjel","kkuopmgz","poeepvcgq","tnmwycn","kceljmum","jnl","juolf","dowo","rrzzxfnkf","thmlunzj","hun","luf","mitvasqf","wmmyfqwdy","ydmxywxkc","hcehuy","ypzctorg","bvjhd","absqpjx","wgbv","sizwh","bjvkkjelk","gddipzpg","fejvx","xoyq","ucc","rkookunou","kuntlxt","zhgxrvxkd","rebrej","vyvilvh","uqtfdnbwt","gpkxvqkzu","ucvhx","yffdbj","hxr","iihnvg","rdxmppncj","idtlj","uhfgj","got","wzbqwpt","khgm","jpijbz","drrv","urffderjf","lza","spmqv","hdkkyv","rwk","xuakeu","dzljg","gsbyb","xehiu","elbt","xxwhs","mtjeftjq","qzmf","saghly","xpimhlx","siqx","celxt","hbjlqoht","ybtvp","hlipjfx","kyusqc","tsv","dtvvm","adertq","uyg","vvr","cbyco","atd","rjc","lfhkihqs","tbuqn","vquox","zgywdhdr","smuk","too","ybbflljww","wrjvi","lfxumyh","tzfzacz","pgwavfhni","xcpomgsa","ewbt","bmygiqf","ctxjep","wchrt","qapafvt","aaislfczf","npjuoek","zodqucxfp","uiqeb","xrzeg","eowil","yvrozikl","bxj","aoeptg","mzibmj","kpkjnqq","pdtqffwq","iev","xfzw","ygxke","hkqvqwls","xwpakuax","gfzzywyib","wtqnkvof","vjgivvel","stggxlb","onjloqlx","rgngsv","nargkejv","fyro","jhbcuvl","snkeom","ruclr","qow");
}
